

package org.madgecko.web;

import java.util.Properties;
import org.springframework.core.io.ClassPathResource;

/**
 * properties属性 暂存器
 */
public class PropertyHolder {
    private static Properties props = new Properties();

    static {
        reload();
    }

    public static Properties getProperties() {
        return props;
    }

    /**
     * 读取各种properties文件
     */
    public static void reload() {
        String developConfig= "/config.properties";
        ClassPathResource cr = null;
        try{
            cr = new ClassPathResource(developConfig);
            props.load(cr.getInputStream());
        }catch(Exception e){
        }
//        String extendPropertyFiles = props.getProperty("extend.property.files");
//        if(extendPropertyFiles!=null && !"".equals(extendPropertyFiles.trim())){
//            String[] files=extendPropertyFiles.trim().split(",");
//            for(String file : files){
//                try{
//                    cr = new ClassPathResource(file);
//                    props.load(cr.getInputStream());
//                }catch(Exception e){
//                }
//            }
//        }
//        for(String propertyName : props.stringPropertyNames()){
//        }
    }

    public static boolean getBooleanProperty(String name) {
        String value = props.getProperty(name);
        return "true".equals(value);
    }

    public static int getIntProperty(String name) {
        String value = props.getProperty(name);

        return Integer.parseInt(value);
    }

    public static String getProperty(String name) {
        String value = props.getProperty(name);

        return value;
    }

    public static void setProperty(String name, String value) {
        props.setProperty(name, value);
    }
}